
using DomainModel.Domain.Model.MessageAssemblyModel;
using DomainModel.Utils;
using NHibernate;
using NHibernate.Criterion;

namespace DomainModel.Infrastructure.Persistence
{
    public class MessageAssembliesRepository : BaseRepository<MessageAssembly, MessageAssemblyId>, IMessageAssembliesRepository
    {
        public MessageAssembliesRepository(ISession session, IApplicationConfig applicationConfig)
            : base(session, applicationConfig)
        {
        }

        public MessageAssembly Get(string hash)
        {
            return Session.CreateCriteria(typeof(MessageAssembly))
               .Add(Restrictions.Eq("Hash", hash))
               .UniqueResult<MessageAssembly>();
        }

        public MessageAssemblyId NextMessageAssemblyId()
        {
            return new MessageAssemblyId(NextIntFromSeq());
        }
    }
}